package yanchun.vip.spring.ioc;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import yanchun.vip.spring.ioc.model.po.User;

@SpringBootApplication
public class SpringIocApplication {


    public static void test(){
        //Spring 框架通过ClassPathXmlApplicationContext 启动容器
        ClassPathXmlApplicationContext ioc = new ClassPathXmlApplicationContext("ioc.xml");


        for (String beanDefinitionName : ioc.getBeanDefinitionNames()) {
            System.out.println("容器中组件的名字:" + beanDefinitionName);
        }
    }

    public static void test1(String[] args) {

        //ApplicationContext：Spring应用上下文，Ioc容器
        ConfigurableApplicationContext ioc = SpringApplication.run(SpringIocApplication.class, args);
        System.out.println("IOC:" + ioc);

        //获取容器中的组件名
        String[] beanDefinitionNames = ioc.getBeanDefinitionNames();
        for (String beanDefinitionName : beanDefinitionNames) {
            System.out.println("容器中组件的名字:"+beanDefinitionName);
        }

        //根据名字获取组件
        Object bleem1 = ioc.getBean("bleem");

        //根据类型获取组件
        Object bleem2 = ioc.getBean(User.class);
    }


    public static void main(String[] args) {
        ConfigurableApplicationContext ioc = SpringApplication.run(SpringIocApplication.class, args);
        System.out.println("IOC容器创建完成");
        System.out.println("============================");
        User bleem = ioc.getBean("bleem", User.class);
        System.out.println("获取组件：" + bleem);
    }

}
